package de.upb.aquarium.api.objects;

import javax.media.opengl.GL;

/**
 * Superclass of all 3D-Objects.
 * Has a position and rotation.
 * @author Alexander
 */
public abstract class General3DObject implements IPaintable {

	private float[] position = new float[] {0,0,0};// default
	private float[] rotation = new float[] {0,0,0};// default


	public General3DObject() {
	}

	protected void beforeRendering(GL gl) {
		gl.glMatrixMode(GL.GL_MODELVIEW);
		gl.glPushMatrix();

		gl.glTranslatef(position[0], position[1], position[2]);
		gl.glRotatef(rotation[2], 0, 0, 1);
		gl.glRotatef(rotation[1], 0, 1, 0);
		gl.glRotatef(rotation[0], 1, 0, 0);
	}

	protected void afterRendering(GL gl) {
		gl.glMatrixMode(GL.GL_MODELVIEW);
		gl.glPopMatrix();
	}

	public float[] getPosition() {
		return position;
	}

	public void setPosition(float[] position) {
		this.position = position;
	}

	public void setPosition(float x, float y, float z) {
		setPosition(new float[] {x,y,z});
	}

	/**
	 * Returns the rotation of the object. The elements of the
	 * returned array are the rotation angles in degrees around
	 * x, y and z axis (in this order), respectively.
	 * @return The rotation angels.
	 */
	public float[] getRotation() {
		return rotation;
	}

	public void setRotation(float[] rotation) {
		this.rotation = rotation;
	}

	public void setRotation(float x, float y, float z) {
		setRotation(new float[] {x,y,z});
	}
}
